a11y: Refactor textcellaccessible code
authorJoanmarie Diggs <jdiggs@igalia.com>
Wed, 25 Mar 2015 02:54:19 +0000 (03:54 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 25 Mar 2015 03:06:23 +0000 (04:06 +0100)
Compute the new text and its length in advance. This way those
computations will not confuse us when they happen in the middle of the
actual action.

https://bugzilla.gnome.org/show_bug.cgi?id=746706

gtk/a11y/gtktextcellaccessible.c

index a5fd435ffe7be5887488aca391c8533adfb03312..1b68c9440add505a3ff7bd21aaf0fad8dd482b4b 100644 (file)
@@ -137,7 +137,7 @@ gtk_text_cell_accessible_update_cache (GtkCellAccessible *cell)
   GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (cell);
   AtkObject *obj = ATK_OBJECT (cell);
   gboolean rv = FALSE;
-  gint temp_length;
+  gint temp_length, text_length;
   gchar *text;
   GtkCellRenderer *renderer;
 
@@ -149,6 +149,10 @@ gtk_text_cell_accessible_update_cache (GtkCellAccessible *cell)
   g_object_get (renderer, "text", &text, NULL);
   g_object_unref (renderer);
 
+  if (text == NULL)
+    text = g_strdup ("");
+  text_length = g_utf8_strlen (text, -1);
+
   if (text_cell->priv->cell_text)
     {
       if (text == NULL || g_strcmp0 (text_cell->priv->cell_text, text) != 0)
@@ -169,16 +173,8 @@ gtk_text_cell_accessible_update_cache (GtkCellAccessible *cell)
 
   if (rv)
     {
-      if (text == NULL)
-        {
-          text_cell->priv->cell_text = g_strdup ("");
-          text_cell->priv->cell_length = 0;
-        }
-      else
-        {
-          text_cell->priv->cell_text = g_strdup (text);
-          text_cell->priv->cell_length = g_utf8_strlen (text, -1);
-        }
+      text_cell->priv->cell_text = g_strdup (text);
+      text_cell->priv->cell_length = text_length;
     }
 
   g_free (text);